#ifndef __STR_EXT_H_H_
#define __STR_EXT_H_H_

#include "stdint.h"
#include "stdlib.h"
#include "string.h"
#include "stdarg.h"

#ifdef __cplusplus
extern "C"
{
#endif

	uint32_t ascii_to_upper(void *pSrc, uint32_t Len); 
	uint32_t ascii_to_lower(void *pSrc, uint32_t Len); 
	uint32_t str_to_upper(void *pSrc);				   
	uint32_t str_to_lower(void *pSrc);				   

	uint32_t ascii_to_upper_with_end(void *Src, uint8_t ch_end, uint32_t Len);
	uint32_t ascii_to_lower_with_end(void *Src, uint8_t ch_end, uint32_t Len);
	uint32_t str_to_upper_with_end(void *Src, char ch_end);
	uint32_t str_to_lower_with_end(void *Src, char ch_end);

	int8_t comp_string(const char *str1, const char *str2, uint32_t Len);		   
	int8_t comp_u8(const void *s1, const void *s2, uint32_t Len);
	int8_t comp_u16(const void *s1, const void *s2, uint32_t Len);
	int8_t comp_u32(const void *s1, const void *s2, uint32_t Len);

	int32_t comp_ix(const void *s1, const void *s2, uint32_t Len);
	int8_t comp_i8(const void *s1, const void *s2, uint32_t Len);
	int16_t comp_i16(const void *s1, const void *s2, uint32_t Len);
	int32_t comp_i32(const void *s1, const void *s2, uint32_t Len);
	int16_t comp_str(const char *str1, const char *str2, uint32_t Len);
	int16_t comp_str_nocase(const char *str1, const char *str2, uint32_t Len); 

	int8_t comp_mem_dat_u8(const void *mem, uint8_t dat, uint32_t Len);
	int8_t comp_mem_dat_u16(const void *mem, uint16_t dat, uint32_t Len);
	int8_t comp_mem_dat_u32(const void *mem, uint32_t dat, uint32_t Len);

	uint32_t diff_u8(const void *s1, const void *s2, uint32_t Len);
	uint32_t diff_u16(const void *s1, const void *s2, uint32_t Len);
	uint32_t diff_u32(const void *s1, const void *s2, uint32_t Len);

	void copy_ux(const void *src, void *des, uint32_t len);									   
	void copy_u8(const void *src, void *des, uint32_t len);									   
	void copy_u16(const void *src, void *des, uint32_t len);								   
	void copy_u32(const void *src, void *des, uint32_t len);								   
	uint32_t copy_str(const void *src, void *des, uint32_t len_max);						   
	void copy_u8_mem_to_dwin(const void *src, int16_t src_size, void *des, int16_t dwin_size); 
	void set_ux(void *des, uint8_t dat, uint32_t len);										   
	void set_u8(void *des, uint8_t dat, uint32_t len);										   
	void set_u16(void *des, uint16_t dat, uint32_t len);									   
	void set_u32(void *des, uint32_t dat, uint32_t len);									   

	int32_t search_1B(const void *src, int32_t src_len, int32_t start, int32_t end, uint8_t dat);
	int32_t search_2B(const void *src, int32_t src_len, int32_t start, int32_t end, uint16_t dat);
	int32_t search_3B(const void *src, int32_t src_len, int32_t start, int32_t end, uint32_t dat);
	int32_t search_4B(const void *src, int32_t src_len, int32_t start, int32_t end, uint32_t dat);

	int32_t poll_search_1B(const void *src, int32_t src_len, int32_t start, int32_t end, uint8_t dat);
	int32_t poll_search_2B(const void *src, int32_t src_len, int32_t start, int32_t end, uint16_t dat);
	int32_t poll_search_3B(const void *src, int32_t src_len, int32_t start, int32_t end, uint32_t dat);
	int32_t poll_search_4B(const void *src, int32_t src_len, int32_t start, int32_t end, uint32_t dat);

	typedef struct
	{
		int32_t src_len, des_len; 
		int32_t start, end;		  
		uint32_t edat;			  

		int32_t res_site; 
		int32_t res_next; 
		int32_t res_len;  
	} e_copy_type;

	int32_t ecopy(e_copy_type *cfg, const void *src, void *des, uint8_t mode);

	int32_t ptr_list_len(const void **list, int32_t len_max); 
	
	uint32_t str_replace_ch(void *dat, uint8_t ch_old, uint8_t ch_new);
	uint32_t str_replace_chs(void *dat, const char *chs_old, uint8_t ch_new);
	uint32_t dat_replace_uch(void *dat, uint8_t ch_old, uint8_t ch_new, uint32_t len);
	uint32_t dat_replace_uchs(void *dat, const uint8_t *chs_old, uint8_t ch_new, uint32_t len);

	uint32_t str_remove_ch(void *dat, uint8_t ch);							   
	uint32_t str_remove_chs(void *dat, const char *chs);					   
	uint32_t str_remove_ch_with_end(void *dat, uint8_t ch_rm, uint8_t ch_end); 
	uint32_t str_remove_ctr_ascii(void *str);								   
	uint32_t str_remove_l20_ascii(void *str);								   
	uint32_t str_remove_la20_ascii_at_tail(void *str);						   
	uint32_t str_remove_tail(void *str);									   
	uint32_t str_remove_low(void *str, uint8_t ch_limite);					   
	uint32_t str_remove_low_head(void *str, uint8_t ch_limite);				   
	uint32_t str_remove_high(void *str, uint8_t ch_limite);					   
	uint32_t str_remove_rang(void *str, uint8_t ch_low, uint8_t ch_high);	   
	uint32_t str_screen_rang(void *str, uint8_t ch_low, uint8_t ch_high);	   
	void str_remove_site(char *str, int32_t site);							   

	int32_t str_remove_str(void *str, const char *rm);			   
	int32_t str_remove_multi_str(void *src, const char *rm);	   
	int32_t str_remove_remul_str(void *src, const char *rm);	   
	int32_t str_replace_str(const char *src, char *des,			   
							const char *old, const char *news);	   
	int32_t str_replace_re_str(char *src,						   
							   const char *old, const char *news); 

	int32_t str_search_ch(const void *dat, uint8_t ch);						  
	int32_t str_search_ch_ext(const void *dat, uint8_t ch, int32_t n);		  
	int32_t str_search_chs(const void *str, const char *chs);				  
	int32_t str_search_chs_ext(const void *str, const char *chs, int32_t n);  
	int32_t str_nsearch_ch(const void *dat, uint8_t ch);					  
	int32_t str_nsearch_ch_ext(const void *dat, uint8_t ch, int32_t n);		  
	int32_t str_nsearch_chs(const void *dat, const char *chs);				  
	int32_t str_nsearch_chs_ext(const void *dat, const char *chs, int32_t n); 
	int32_t str_ch_amount(const void *dat, uint8_t ch);						  
	int32_t str_search_ch_ge(const void *dat, uint8_t ch);					  
	int32_t str_search_ch_le(const void *dat, uint8_t ch);					  

	int32_t str_get_line_site_list(const void *src, int32_t *des, int32_t max_len); 
	int32_t str_site_next_line(const void *src, int32_t site_now);					
	int32_t str_get_inum_site_list(const void *src, int32_t *des, int32_t max_len); 
	int32_t str_get_fnum_site_list(const void *src, int32_t *des, int32_t max_len); 
	int32_t str_search_inumch(const void *dat);										
	int32_t str_search_fnumch(const void *dat);										
	int32_t str_search_str(const void *src, const void *str);						
	int32_t str_nsearch_str(const void *src, const void *str);						
	int32_t str_get_line(const void *src, void *des);								
	int32_t str_get_str(const void *src, void *des, uint8_t end_ch);				
	int32_t str_get_fnumstr(const void *src, void *des, int32_t len_max);			
	int32_t str_search_get_fnumstr(const void *src, void *des, int32_t len_max);	
	int32_t str_get_inumstr(const void *src, void *des, int32_t len_max);			
	int32_t str_search_get_inumstr(const void *src, void *des, int32_t len_max);	
	uint16_t str_is_fnum(const void *src);											
	uint16_t str_is_inum(const void *src);											
	void str_insert_ch(char *str, int32_t site, char ch);							
	void str_add(char *str, const char *str_add, int32_t str_len_max);				
	void str_insert_str(char *str, int32_t site, const char *str_in);				
	int32_t str_split(char *str, char ch, char **des, int32_t des_max);				
	int32_t str_splits(char *str, const char *chs, char **des, int32_t des_max);	

	int is_str_empty(char* str); 

	void dat8_insert(uint8_t *list, uint16_t size, uint16_t site, uint8_t dat_in);
	void dat16_insert(uint16_t *list, uint16_t size, uint16_t site, uint16_t dat_in);
	void dat32_insert(uint32_t *list, uint16_t size, uint16_t site, uint32_t dat_in);
	
	void str_add_ch(char * str, char ch, int amount); 
	void str_add_ch_to_length(char * str, char ch, int length); 

	int32_t str_to_i32_array(const void *src, int32_t *des, int32_t max_len);
	int32_t str_to_i16_array(const void *src, int16_t *des, int32_t max_len);
	int32_t str_to_i8_array(const void *src, int8_t *des, int32_t max_len);
	int32_t str_to_float_array(const void *src, float *des, int32_t max_len);

	typedef struct
	{
		char *str;
		int32_t len_max;
		int32_t next;
		int32_t search_site;
	} str_obj_type;

	int32_t str_obj_new(str_obj_type *obj, char *str, int32_t len_max, char mode); 
	int32_t str_obj_add_ch(str_obj_type *obj, char ch);
	int32_t str_obj_add_str(str_obj_type *obj, const char *str);
	int32_t str_obj_add_i32(str_obj_type *obj, int32_t ival, uint8_t ip_n, uint8_t attr);

	int32_t str_obj_search_site_reset(str_obj_type *obj, int32_t site);		   
	int32_t str_obj_search_ch(str_obj_type *obj, char ch);					   
	int32_t str_obj_nsearch_ch(str_obj_type *obj, char ch);					   
	int32_t str_obj_getline(str_obj_type *obj, char *des, int32_t des_length); 

	int32_t str_obj_poll_add_ch(str_obj_type *obj, char ch);
	int32_t str_obj_poll_add_str(str_obj_type *obj, const char *str);
	int32_t str_obj_poll_getline(str_obj_type *obj, char *des, int32_t des_length);

	const char *file_name_get(const char *file_path);
	const char *file_type_get(const char *file_path);
	int file_name_format(char *file_name); 
	
	int str_snprintf(char *buf, size_t size, const char *fmt, ...);
	int str_printf(char *buf, const char *fmt, ...);
	int str_vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
	
	int strx_fmt(char *buf, const char *fmt, ...);
	int strx_vfmt(char *buff, const char *str, va_list args);
	
#ifdef __cplusplus
}
#endif

#endif 
